package com.aweqy.porcelain.controller;

import com.aweqy.porcelain.common.BaseResponse;
import com.aweqy.porcelain.common.ResultUtils;
import com.aweqy.porcelain.entity.CeramicProduct;
import com.aweqy.porcelain.service.CeramicProductService;
import com.aweqy.porcelain.common.DeleteRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

/**
 * 陶瓷产品相关接口
 */
@RestController
@RequestMapping("/api/ceramic_product")
@CrossOrigin
public class CeramicProductController {
    @Autowired
    private CeramicProductService ceramicProductService;

    /**
     * 获取所有陶瓷产品信息
     * @return 所有陶瓷产品列表
     */
    @GetMapping("/list")
    public BaseResponse<List<CeramicProduct>> list() {
        return ResultUtils.success(ceramicProductService.list());
    }

    /**
     * 根据ID获取陶瓷产品详情
     * @param id 产品ID
     * @return 陶瓷产品详细信息
     */
    @GetMapping("/{id}")
    public BaseResponse<CeramicProduct> getById(@PathVariable Integer id) {
        return ResultUtils.success(ceramicProductService.getById(id));
    }

    /**
     * 新增陶瓷产品信息
     * @param entity 陶瓷产品实体
     * @return 是否新增成功
     */
    @PostMapping("/add")
    public BaseResponse<Boolean> add(@RequestBody CeramicProduct entity) {
        return ResultUtils.success(ceramicProductService.save(entity));
    }

    /**
     * 更新陶瓷产品信息
     * @param entity 陶瓷产品实体
     * @return 是否更新成功
     */
    @PostMapping("/update")
    public BaseResponse<Boolean> update(@RequestBody CeramicProduct entity) {
        return ResultUtils.success(ceramicProductService.updateById(entity));
    }

    /**
     * 删除陶瓷产品信息
     * @param request 删除请求，包含主键ID
     * @return 是否删除成功
     */
    @PostMapping("/delete")
    public BaseResponse<Boolean> delete(@RequestBody DeleteRequest request) {
        return ResultUtils.success(ceramicProductService.removeById(request.getId()));
    }
} 